package edu.qd.learn.day03;

/**
 * 青蛙跳井
 *
 * @author 布衣
 */
public class FrogJumpWell {

    /**
     * @param height 井深
     * @param jump   跳几米
     * @param down   滑几米
     * @return
     */
    public int jump(int height, int jump, int down) {
        //临界
        jumpForException(height, jump, down);

        int num = 0;
        for (int i = 0; (i += jump) < height & num++ >= 0; i -= down) {
        }
        return num;
    }

    public void jumpForException(int height, int jump, int down){
        //临界
        if(jump > height){
            throw new RuntimeException("对不起,跳的高度大于高度");
        }
        if(height < 0 || jump < 0 || down <0){
            throw new RuntimeException("对不起参数传递错误");
        }
        if(down > jump){
            throw new RuntimeException("对不起参数传递错误");
        }
        if(height == 0){
            throw new RuntimeException("对不起,跳的高度大于高度");
        }

    }

    public int jumpWhile(int height, int jump, int down) {
        jumpForException(height, jump, down);
        int num = 0;
        int i = 0;
        while ((i += jump) < height & num++ >= 0) {
            i -= down;
        }
        return num;
    }

    public int jumpDoWhile(int height, int jump, int down) {
        jumpForException(height, jump, down);
        int num = 0;
        int i = 0;
        do {
        } while (((i += jump) < height) & (num++ >= 0) &( (i-=down) > 0));
        return num;
    }

    public static void main(String[] args) {
        FrogJumpWell f = new FrogJumpWell();
        System.out.println(f.jumpWhile(4, 3, 1));
    }

}
